<!doctype html>
<html>
  <head>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-132775238-1"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'UA-132775238-1');
    </script>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;600&family=Roboto+Mono&display=swap" rel="stylesheet">
    <style>
      .btn{
        width: 70px;
        height: 70px;
        background-color: #47AFE8;
        color: #fff;
        font-size: 12px;
        display: block;
        border: none;
        margin: 2px;
        border-radius: 2px;
        cursor:pointer;
        outline:none;
      }
      rapi-doc{
        width:100%;
      }
    </style>
    <script type="text/javascript" src="../rapidoc-min.js"></script>
    <script>
      function getRapiDoc(){
        return document.getElementById("thedoc");
      }  
    
      function changeRenderStyle() {
        let currRender = getRapiDoc().getAttribute('render-style');
        let newRender = currRender === "read" ? "view" : "read";
        getRapiDoc().setAttribute('render-style', newRender );
      }

      function toggleAttr(attr){
        if (getRapiDoc().getAttribute(attr) === 'false'){
          getRapiDoc().setAttribute(attr,"true");
        }
        else{
          getRapiDoc().setAttribute(attr,"false");
        }
      }
    
      function changeFont(){
        if (getRapiDoc().getAttribute('regular-font') === "'Varela Round'"){
          getRapiDoc().setAttribute('regular-font',"'rapidoc'");
        }
        else{
          getRapiDoc().setAttribute('regular-font',"'Varela Round'");
        }
      }

      // DOM Ready !!!
      window.addEventListener('DOMContentLoaded', (event) => {
        const urlParams = new URLSearchParams(window.location.search);

        let specUrl = urlParams.get('spec');
        const baseTheme = urlParams.get('theme');
        const renderStyle = urlParams.get('render-style');
        const bgColor = urlParams.get('bg-color');
        const textColor = urlParams.get('text-color');
        const navBg = urlParams.get('nav-bg');
        const primaryColor = urlParams.get('primary-color');
        const goto = urlParams.get('goto');
        const rapidocEl = getRapiDoc();
        rapidocEl.addEventListener('spec-loaded', e => console.log(e.detail));
        
        if(!specUrl) {
          specUrl = '../specs/petstore.json'
          // specUrl = '../specs/petstore_extended.yaml'
        }
        rapidocEl.setAttribute('render-style', 'read');
        console.log('render-style must be read , actually value is %s', rapidocEl.getAttribute('render-style'));
        rapidocEl.setAttribute('render-style', 'view');
        console.log('render-style must be view , actually value is %s', rapidocEl.getAttribute('render-style'));

        if (baseTheme) {
          rapidocEl.setAttribute('theme', baseTheme);
        }
        if (renderStyle) {
          rapidocEl.setAttribute('render-style', renderStyle);
        }
        if (bgColor) {
          rapidocEl.setAttribute('bg-color', `#${bgColor}`);
        }
        if (textColor) {
          rapidocEl.setAttribute('text-color', `#${textColor}`);
        }
        if (navBg) {
          rapidocEl.setAttribute('nav-bg-color', `#${navBg}`);
        }
        if (goto) {
          rapidocEl.setAttribute('goto-path', goto);
        }
        if (baseTheme) {
          rapidocEl.setAttribute('theme', baseTheme);
        }
        if (specUrl) {
          rapidocEl.setAttribute('spec-url',specUrl);
        }
      });

    </script>
  </head>
  <body>
    <rapi-doc id="thedoc" regular-font='Open Sans' mono-font = "Roboto Mono"> </rapi-doc>
  </body>
</html>